import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/supplier/supplier_list_page.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/router/router_map.gr.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/widgets/base_appbar.dart';
import 'package:tender_flutter/widgets/sticky_tabbar_delegate.dart';

class TabSupplierPage extends StatefulWidget {
  @override
  _TabSupplierPageState createState() => _TabSupplierPageState();
}

class _TabSupplierPageState extends State<TabSupplierPage>
    with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ThemeColors.colorType11,
      appBar: _initAppBar(),
      body: _initBody(),
    );
  }

  /// 导航栏
  Widget _initAppBar() {
    return BaseAppBar(
      context,
      GestureDetector(
          onTap: () {
            LRouter.navigatorCtx(context).push(Routes.supplierSearchPage);
          },
          child: Container(
            width: double.infinity,
            height: ScreenAdapter.height(60),
            decoration: BoxDecoration(
              color: ThemeColors.colorType5,
              borderRadius:
                  BorderRadius.all(Radius.circular(ScreenAdapter.width(14))),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Image.asset(RPath.imgPath + "icon_gray_search.png",
                    width: ScreenAdapter.width(30)),
                SizedBox(width: ScreenAdapter.width(18)),
                Text(
                  "请输入招标关键词进行搜索",
                  style: TextStyle(
                      color: ThemeColors.colorType3,
                      fontSize: ScreenAdapter.sp(30)),
                )
              ],
            ),
          )),
      isShowLeading: false,
    );
  }

  /// 内容体
  Widget _initBody() {
    return NestedScrollView(
      headerSliverBuilder: (context, innerScrolled) => <Widget>[
        SliverOverlapAbsorber(
          // 传入 handle 值，直接通过 `sliverOverlapAbsorberHandleFor` 获取即可
          handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
          sliver: SliverAppBar(
            backgroundColor: Colors.transparent,
            elevation: 1,
            expandedHeight: ScreenAdapter.height(220),
            stretch: true,
            flexibleSpace: FlexibleSpaceBar(
              background: _initAddImage(),
              collapseMode: CollapseMode.parallax,
              stretchModes: [
                StretchMode.zoomBackground,
                StretchMode.blurBackground,
                StretchMode.fadeTitle,
              ],
            ),
          ),
        ),
        SliverPersistentHeader(
          pinned: true,
          delegate: StickyTabBarDelegate(
            minHeight: ScreenAdapter.height(80),
            maxHeight: ScreenAdapter.height(80),
            child: _initTitleView(),
          ),
        ),
      ],
      body: SupplierListPage(supplietType: AppConstant.SUPPLIER_ALL),
    );
  }

  /// 加入供应商按钮
  Widget _initAddImage() {
    return GestureDetector(
        onTap: () {
          LRouter.navigatorCtx(context).push(Routes.supplierJoinPage);
        },
        child: Container(
            width: double.infinity,
            height: double.infinity,
            padding: EdgeInsets.only(
                top: ScreenAdapter.width(30),
                left: ScreenAdapter.width(30),
                right: ScreenAdapter.width(30)),
            child: ClipRRect(
                borderRadius: BorderRadius.circular(ScreenAdapter.width(15)),
                child: Image.asset(
                  RPath.imgPath + "img_join_supplier.png",
                  fit: BoxFit.cover,
                ))));
  }

  /// 标题
  Widget _initTitleView() {
    return Container(
        width: double.infinity,
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(35)),
        color: ThemeColors.colorType11,
        child:
            Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
          Expanded(
              child: Text(
            "供应商推荐",
            style: TextStyle(
                color: ThemeColors.colorType1,
                fontSize: ScreenAdapter.sp(35),
                fontWeight: FontWeight.bold),
          )),
          InkWell(
              onTap: () {
                LRouter.navigatorCtx(context).push(Routes.supplierListMorePage);
              },
              child: Row(children: [
                Text(
                  "查看更多",
                  style: TextStyle(
                      color: ThemeColors.colorType3,
                      fontSize: ScreenAdapter.sp(26),
                      fontWeight: FontWeight.bold),
                ),
                // Icon(Icons.read_more, color: ThemeColors.colorType3),
              ]))
        ]));
  }
}
